import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class OriginalMethod {
    public List GetPath(File dir) {
        File[] files = dir.listFiles();
        List<File> files1 = new ArrayList<>();
        for(int i=0;i<files.length;i++){
            files1.add(files[i]);
        }
        for (int i=0;i<files1.size();i++) {
            File f = files1.get(i);
            if (f.isDirectory()) {
                for(File file : show2(f)){
                    files1.add(file);
                }
            }
        }
        return files1;
    }

    public  File[] show2(File file){
        File[] files = file.listFiles();
        return files;
    }

    public void CreatNewFile(File file){
        File fileParent = file.getParentFile();
//判断是否存在
        if (!fileParent.exists()) {
            fileParent.mkdirs();
        }
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void Delete(File del){
        if (!del.exists()){
            return;
        }
        if (del.isFile()){
            del.delete();
        }
        for (File file : del.listFiles()){
            Delete(file);
        }
        del.delete();
    }

    public void Copy(File FileName, File target) {
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;

        byte[] b = new byte[1024];
        int len = 0;
        try {
            bis = new BufferedInputStream(
                    new FileInputStream(FileName)
            );
            bos = new BufferedOutputStream(
                    new FileOutputStream(target)
            );

            while ((len = bis.read(b)) != -1) {
                bos.write(b, 0, len);//粘贴
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            bis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public File CreatNewFileName(File Filename, File target){
        StringBuffer filename1 = new StringBuffer();
        StringBuffer filename2 = new StringBuffer();
        filename1.append(Filename.getPath());
        filename2.append(target.getPath());
        filename1.delete(0,2);
        filename1.insert(0,target);
        if (filename2.length()==3&&(filename1.substring(0,3).equals(filename2.substring(0,3)))){
            filename1.insert(filename1.indexOf("\\",4),"1");
        }
        File file = new File(String.valueOf(filename1));
        return file;
    }
    public File GetChildPath(File file,StringBuffer ChildPath){
        StringBuffer Path1 = new StringBuffer();
        Path1.append(file.getPath());
        Path1.delete(0,Path1.indexOf(new String(ChildPath)));
        File file1 = new File(String.valueOf(Path1));
        return file1;
    }
}
